﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CoolChat
{
    public partial class getMessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                NewMethod();
            }
            catch (Exception ex)
            {
                Response.Write("parameters error or occur a server error,plz check and try again."+ex);
            }
        }

        private void NewMethod()
        {
            string type = Request["t"];
            string beforeTime = Request["bt"];
            string endTime = Request["et"];
            string keyWord = Request["w"];
            string userName = Request["n"];
            string order = Request["o"];
            string count = Request["c"];
            List<ChatMessage> ms = Dbo.SelectMsgs(
                string.IsNullOrEmpty(type) ? -1 : int.Parse(type),
                string.IsNullOrEmpty(beforeTime) ? DateTime.MinValue : DateTime.Parse(beforeTime),
                string.IsNullOrEmpty(endTime) ? DateTime.MinValue : DateTime.Parse(endTime),
                keyWord, userName, string.IsNullOrEmpty(order) ? -1 : int.Parse(order),
                string.IsNullOrEmpty(count) ? -1 : int.Parse(count));
            string json = LitJson.JsonMapper.ToJson(ms.ToArray());
            Response.Write(json);
        }
    }
}